/* 1.导入koa模块 */
const koa = require("koa");
/* 1.导入路由 */
const router =new require("koa-router")();
const app =new koa();
/* router.get("/my",async ctx=>{
    ctx.body ={
        code:200,
        msg:"my"
    }
})
router .get("/friend",async ctx=>{
    ctx.body ={
        code:200,
        msg:"friend"
    }
}) */
const data =require("./data/data")
router .get("/top/playlist",async ctx=>{
    console.log(ctx.request.query)
    var {offset,limit}=ctx.request.query;
    console.log(offset)
    offset=Number(offset)
    limit=Number(limit)
    var result=data.result;
    if(!offset){
        offset=0
    }
    if(!limit){
        limit=5
    }
    ctx.body={
        code:200,
        data:result.slice(offset,offset+limit),
        total:result.length
    };
})
/* 配置路由 */
app.use(router.routes())
/* 2.新建一个应用 */
/* const app =new koa(); */
/* 给前端返回值 */
// app.use(async ctx=>{
//     ctx.body ="hello world"
// })
/* 4. app监听8080 */
app.listen(7000,function(){
    console.log("开始")
})
